import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/cupertino.dart';
import 'package:ls_work/net/api/samrt_equipment_api.dart';

import '../../net/post_request.dart';
import '../../net/response/iot/mattress_detail_data.dart';
import '../../net/response/iot/smart_equipment_data.dart';

class IotModel extends BaseMvvmModel {
  @override
  void onCleared() {}

  ///设备列表
  Future<List<SmartEquipmentData>> getEquipmentList(
      {required int page, required int rows, bool wrapper = true}) async {
    var map = {
      "page": page,
      "rows": rows,
      "wrapper": wrapper,
    };

    var data = await HttpGo.instance
        .postData(SmartEquipmentApi.equipmentList, data: map);
    if ("0" == data['code']) {
      var list = ((data['data']['rows'] as List) ?? [])
          .map((e) => SmartEquipmentData.fromJson(e))
          .toList();
      return list;
    } else {
      throw data['message'];
    }
  }

  ///床垫详情
  Future<MattressRecordData> getMattressDetail({String? date, String? iotCode}) async {
    var map = {"date": date, "iotCode": iotCode};
    var data = await HttpGo.instance.postData(SmartEquipmentApi.mattressDetail,
        data: map, options: PostRequest.urlencodedHeader);
    if("0"==data['code']){
      var bean = MattressRecordData.fromJson(data['data']);
      return bean;
    }else{
      throw data['message'];
    }
  }
}
